package ThreadTest;

import com.xx.doublexchat.common.DoublexChatCustomApplication;
import com.xx.doublexchat.common.common.thread.MyUncaughtExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = DoublexChatCustomApplication.class)
@RunWith(SpringRunner.class)
@Slf4j
public class test {
    @Qualifier("doubleXChatExecutor")
    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
    @Test
    public void thread() throws InterruptedException {
        Thread thread = new Thread(() ->{
            if (1==1) {
                log.error("123");
                throw new RuntimeException("test");
            }
        });
        thread.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
        thread.start();
        Thread.sleep(200);
    }


    @Test
    public void testMyThread() throws InterruptedException {
        threadPoolTaskExecutor.execute(() -> {
            if (1==1) {
                log.error("123");
                throw new RuntimeException("test");
            }
        });
        Thread.sleep(200);
    }
}
